﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mesoBoard.Web.Core;
using mesoBoard.Data;

namespace mesoBoard.Web.Areas.Admin.Controllers
{
    public class BBCodesController : mesoBoardAdminController
    {
        [HttpGet]
        public ActionResult BBCodes()
        {
            SetCrumb("BB Codes");
            return View(Repositories.BBCodes.GetBBCodes());
        }

        [HttpPost]
        public ActionResult BBCodes(BBCode TheBBCode)
        {
            SetCrumb("BB Codes");

            if (ModelState.IsValid)
            {
                Repositories.BBCodes.CreateBBCode(TheBBCode);
                SetSuccess("BB Code created");
            }
            else
            {
                SetError("BB Code Validation Error");
            }
            return View(Repositories.BBCodes.GetBBCodes());
        }

        public ActionResult DeleteBBCode(int BBCodeID)
        {
            Repositories.BBCodes.DeleteBBCode(BBCodeID);
            SetSuccess("BB Code deleted");
            return RedirectToAction("BBCodes");
        }

        [HttpGet]
        public ActionResult EditBBCode(int BBCodeID)
        {
            SetCrumb("BB Codes");

            return View(Repositories.BBCodes.GetBBCode(BBCodeID));
        }

        [HttpPost]
        public ActionResult EditBBCode(BBCode TheBBCode)
        {
            SetCrumb("BB Codes");

            if (ModelState.IsValid)
            {
                Repositories.BBCodes.SaveBBCode(TheBBCode);
                SetSuccess("BB Code edited");
                return RedirectToAction("BBCodes");
            }
            else
            {
                SetError("Invalid BB Code data");
                return View(TheBBCode);
            }
        }

    }
}
